/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.src.uniandes.ecos.tsp.creditscore.algorithm;

import com.src.uniandes.ecos.tsp.creditscore.base.GeneralConstants;
import com.src.uniandes.ecos.tsp.creditscore.exception.CreditScoreException;

/**
 *
 * @author AndhyMao
 */
public class CreditScoreAlgorithm {

    protected static CreditScoreAlgorithm creditScoreAlgorithm;

    public static CreditScoreAlgorithm getInstance() {
        if (creditScoreAlgorithm == null) {
            creditScoreAlgorithm = new CreditScoreAlgorithm();
        }
        return creditScoreAlgorithm;
    }

    public double calculateCreditScore (Integer cliCodigo) throws CreditScoreException {
        double points = 0;
        double pointsPaymentHistory = 0;
        double pointsAmountsOwed = 0;
        double pointsLongCreditHistory = 0;
        double pointsNewCredit = 0;
        double pointsTypesOfCreditUsed = 0;
        try {
            /**
             * PaymentHistory 
             */
            PaymentHistory paymentHistory = new PaymentHistory();
            pointsPaymentHistory = paymentHistory.getPointsPaymentHistory(cliCodigo);

            /**
             * AmountsOwed
             */
            AmountsOwed amountsOwed = new AmountsOwed();
            pointsAmountsOwed = amountsOwed.getPointTotalDebt(cliCodigo);

            /**
             * LongCreditHistory
             */
            LongCreditHistory longCreditHistory = new LongCreditHistory();
            pointsLongCreditHistory = longCreditHistory.getPointsLongCreditHistory(cliCodigo);

            /**
             * NewCredit
             */
            NewCredit newCredit = new NewCredit();
            newCredit.getPointsNewCredit(cliCodigo);

            /**
             * TypesOfCreditUsed
             */
            TypesOfCreditUsed typesOfCreditUsed = new TypesOfCreditUsed();
            pointsTypesOfCreditUsed = typesOfCreditUsed.getPointCreditType(cliCodigo);

            points = pointsPaymentHistory + pointsAmountsOwed + pointsLongCreditHistory + pointsNewCredit + pointsTypesOfCreditUsed;

            points = ((points / 100) * 550) + 300;
            
            return points;
        }
        catch (Exception e) {
            throw new CreditScoreException("CreditScoreAlgorithm:calculateCreditScore:" + e.toString(), e);
        }
    }
}
